#
#__str__,__iter__,__getitem__

class Fib(object):
    def __init__(self):
        self.a,self.b=0,1

    def __iter__(self):
        return self

    def __next__(self):
        self.a,self.b=self.b,self.a+self.b
        if self.a>1000:
            raise StopIteration
        return self.a
    #"""def __getitem__(self,n):
    #   a,b=1,1
    #   for x in range(n):
    #       a,b=b,a+b
    #   return a"""
    def __getitem__(self,n): #n is int,or a slice object
        if isinstance(n,int):
            a,b=1,1
            for x in range(n):
                a,b=b,a+b
            return a
        if isinstance(n,slice):
            start=n.start
            stop=n.stop
            if start is None:
                start=0
            a,b=1,1
            l=[]
            for x in range(stop):
                if x>=start:
                    l.append(a)
                a,b=b,a+b
            return l
#__getattr__
class Student(object):
    def __getattr__(self,attr):
        if attr=="age":
            return lambda :25
        raise AttributeError('\'Student\'object has no attribute\
\'%s\''%attr)
    def __call__(self):
        print('My name is ...')
        
class Chain(object):

    def __init__(self,path=''):
        self._path=path
    def __getattr__(self,path):
        return Chain('%s/%s'%(self._path,path))
    def __str__(self):
        return self._path
    __repr__=__str__
#__calss__ ,instance.method()
#callcble()函数可以判断一个对象是否是‘可调用’对象
